use std::env;
use std::process;
pub unsafe fn atoi(str: *const i8) -> i32 {
    let mut result = 0;
    let mut sign = 1;
    let mut ptr = str;
    while *ptr == b' ' as i8
        || *ptr == b'\t' as i8
        || *ptr == b'\n' as i8
        || *ptr == b'\r' as i8
        || *ptr == 0x0B_i8
        || *ptr == 0x0C_i8
    {
        ptr = ptr.offset(1);
    }
    if *ptr == b'+' as i8 || *ptr == b'-' as i8 {
        if *ptr == b'-' as i8 {
            sign = -1;
        }
        ptr = ptr.offset(1);
    }
    while *ptr >= b'0' as i8 && *ptr <= b'9' as i8 {
        let digit = *ptr - b'0' as i8;
        if result > i32::MAX / 10 || (result == i32::MAX / 10 && digit > 7) {
            return if sign == 1 { i32::MAX } else { i32::MIN };
        }
        result = result * 10 + digit as i32;
        ptr = ptr.offset(1);
    }
    sign * result
}
pub fn main() {
    let args: Vec<String> = env::args().collect();
    if args.len() != 2 {
        eprintln!("Usage: {} <number>", args[0]);
        process::exit(1);
    }
    let value = unsafe { atoi(args[1].as_ptr() as *const i8) };
    println!("Parsed integer: {}", value);
}
